<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action = $_REQUEST['act'];
	$start		=	$_REQUEST['start'];
    $end		=	$_REQUEST['end'];
	
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("SELECT 		pos_money_action_old.id AS `id`,
												DATE(pos_money_action_old.date) AS `date`,
												TIME(pos_money_action_old.date) AS  `time`,
												IF(pos_money_action_old.action = 1, pos_money_action_old.money, '') AS `in`,
												IF(pos_money_action_old.action = 2, pos_money_action_old.money, '') AS `out`,
												sale_transaction_old.car_number AS `car`,
												sale_transaction_old.payed_money AS `payed_money`,
												ROUND(sale_transaction_old.payed_money - sale_transaction_old.sum_cost, 2) AS `coin`,
												IF(sale_transaction_old.pay_type = 1, 'ნაღდი', 'უნაღდო') AS `pay_type`,
												persons.`name` AS `person`,
												obj1.`name` AS `object`,
												obj2.`name`,
												pos_money_action_old.`comment`
									FROM 		`pos_money_action_old`
									LEFT JOIN  	sale_transaction_old ON pos_money_action_old.sale_transaction_id = sale_transaction_old.id
									LEFT JOIN 	users ON pos_money_action_old.user_id = users.id
									LEFT JOIN 	persons ON users.person_id = persons.id
									LEFT JOIN 	object  AS `obj1` ON pos_money_action_old.pos_id = obj1.id
									LEFT JOIN 	object  AS `obj2` ON obj1.parent = obj2.id
									WHERE     	pos_money_action_old.date  BETWEEN  '$start'  AND '$end'
									");
			
			$output = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$output['aaData'][] = $row;
			}
			
			echo json_encode( $output );

	        break;	    
	    default:
	       	echo "null";
	}
?>